package com.health.trans.config.dataSource;

import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author nqlz
 */
@Component
@RequiredArgsConstructor
public class DynamicDsConf {

    private final ApplicationContext applicationContext;

    @ConfigurationProperties(prefix = "spring.datasource.dynamic")
    @Data
    @Component
    static class DsMap {
        private Map<String, DsProperty> datasource = new LinkedHashMap<>();
    }

    public Map<String, DsProperty> getDsProperties() {
        return applicationContext.getBean(DsMap.class).getDatasource();
    }

}
